package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.*;
import cn.wolfcode.trip.base.mapper.GrogshopCommentMapper;
import cn.wolfcode.trip.base.mapper.GrogshopMapper;
import cn.wolfcode.trip.base.query.GrogshopQuery;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IGrogshopService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IGrogshopServiceImpl implements IGrogshopService {

    @Autowired
    private GrogshopMapper grogshopMapper ;
    @Autowired
    private GrogshopCommentMapper grogshopCommentMapper;


    @Override
    public void saveOrUpdate(Grogshop grogshop) {
        if (grogshop.getId()!=null) {
            grogshopMapper.updateByPrimaryKey(grogshop);
            //在保存文章
            GrogshopComment comment = grogshop.getGrogshopComment();
            comment.setId(grogshop.getId());
            grogshopCommentMapper.updateByPrimaryKey(comment);

        }else {
            //先保存基本信息
            grogshopMapper.insert(grogshop);
            //在保存文章
           /* GrogshopComment comment = grogshop.getGrogshopComment();
            comment.setId(grogshop.getId());
            grogshopCommentMapper.insert(comment);*/
        }
    }

    //查询所有有信息
    @Override
    public List<Grogshop> listAll() {
        return grogshopMapper.selectAll();
    }

    @Override
    public PageInfo<Grogshop> query(GrogshopQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<Grogshop> list = grogshopMapper.selectForList(qo);
        return new PageInfo(list);
    }


    //根据酒店的id查询详情
    @Override
    public List<Grogshop> getGrogshopById(Long id) {

        return grogshopMapper.selectForAll(id);
    }

    @Override
    public GrogshopComment selectContentById(Long id) {
        return grogshopCommentMapper.selectByPrimaryKey(id);
    }

    //根据酒店的id查询文章内容
    @Override
    public GrogshopComment getCommetnById(Long id) {

        return grogshopCommentMapper.selectByPrimaryKey(id);
    }

}
